package main

import "fmt"

type Person struct {
	name string
	age  int
}
type mystr string
type Student struct {
	Person //结构体匿名字段 通过匿名字段继承
	mystr  //非结构体匿名字段
	xuehao int
	sort   int
}

//面向对象方法定义
func (temp Student) StudentPrint() {
	fmt.Printf("StudentPrint address2 %p \n", &temp)

	fmt.Println("自定义结构体的对象方法StudentPrint:", temp)
}

//面向对象方法定义
func (temp Student) studentPrint() {
	fmt.Println("自定义结构体的对象方法studentPrint:", temp)
}

//可以用*type定义,但是对象方法本身不能使用指针定义
func (t *Student) UpdateStudent(a, c int, b string) {
	fmt.Printf("address2 %p \n", t)
	//	t.age = a
	t.Person.age = a
	t.name = b
	t.xuehao = c
}

type Teacher struct {
	Person
	bianhao int
}
type xiaozhang struct {
	*Person //结构体指针类型匿名字段
	high int
}

func main() {

	stu1 := Student{}
	stu1.Person.name = "stu1_name"
	stu1.xuehao = 1
	stu1.mystr = "str1"
	fmt.Println(stu1)
	fmt.Println(stu1.Person)

	fmt.Println("--------自定义结构体的对象方法-----------")
	stu1.StudentPrint()
	fmt.Printf("address 1: %p \n", &(stu1))
	(&stu1).UpdateStudent(25, 26, "hi")
	(stu1).UpdateStudent(26, 26, "hi")
	stu1.studentPrint()
	fmt.Println("-------------------")

	per1 := new(Person) //new(type)返回的已经是内存空间地址
	per1.name = "per1"
	per1.age = 22

	xiaozhang1 := xiaozhang{per1, 170}
	fmt.Println(xiaozhang1, *xiaozhang1.Person)

	per2 := Person{}
	per2.age = 23
	xiaozhang2 := xiaozhang{&per2, 170}
	fmt.Println(xiaozhang2, *xiaozhang2.Person)
}
